package org.example.controller;

import org.apache.ibatis.annotations.Param;
import org.example.domain.EmailRecord;
import org.example.service.impl.EmailRecordServiceImpl;
import org.example.untils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("emailRecord")
public class EmailRecordController {

    @Autowired
    private EmailRecordServiceImpl emailRecordServiceImpl;

    @PostMapping("/addEmailRecord")
    public Result addEmailRecord(@RequestBody() EmailRecord emailRecord){
        emailRecordServiceImpl.addEmailRecord(emailRecord);
        return new Result(200,"发送成功",null);
    }

    @GetMapping("/getEmailRecordsByUserId")
    public Result getEmailRecordsByUserId(@Param("userId") Integer userId,@Param("start") Integer start){
        EmailRecord[] emailRecords= emailRecordServiceImpl.getEmailRecordsByUserId(userId,start);
        return new Result(200,"获取成功",emailRecords);
    }

    @GetMapping("/getEmailRecordsByAdminIdZero")
    public Result getEmailRecordsByAdminIdZero(@Param("start") Integer start){
        EmailRecord[] emailRecords= emailRecordServiceImpl.getEmailRecordsByAdminIdZero(start);
        return new Result(200,"获取成功",emailRecords);
    }

    @GetMapping("/getEmailRecordsByAdminIdNotZero")
    public Result getEmailRecordsByAdminIdNotZero(@Param("start") Integer start){
        EmailRecord[] emailRecords= emailRecordServiceImpl.getEmailRecordsByAdminIdNotZero(start);
        return new Result(200,"获取成功",emailRecords);
    }

    @PostMapping("/replyEmailRecordById")
    public Result replyEmailRecordById(@RequestBody() EmailRecord emailRecord){
        emailRecordServiceImpl.replyEmailRecordById(emailRecord);
        return new Result(200,"答复成功",null);
    }
}
